package cn.xshi.bpm.web;

import cn.xshi.bpm.model.LcStatus;
import cn.xshi.bpm.service.LcStatusService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.base.BaseSearch;
import cn.xshi.common.entity.OauthAccountEntity;
import cn.xshi.common.util.StringUtil;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Desc 流程状态
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Api(value = "流程状态", description = "流程状态",tags = "流程状态")
@RestController
@RequestMapping("/lcStatus")
public class LcStatusController extends BaseAction {

	@Resource
	private LcStatusService lcStatusService;

	/**
	 * 查询并分页
	 * @param baseSearch
	 */
	@ApiOperation(value="查询并分页", notes="查询并分页")
	@PostMapping(value="/list")
	@Auth(value = "/lcStatus/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BasePage<List<LcStatus>> getLcStatusListByCondition(@RequestBody BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<LcStatus> lcStatusList = lcStatusService.getLcStatusListByCondition(condition);
		for(LcStatus lcStatus:lcStatusList){
			if(!StringUtil.isEmpty(lcStatus.getCreateId())){
				OauthAccountEntity createBy = getAccount(lcStatus.getCreateId());
				if(null != createBy){
					lcStatus.setCreateBy(createBy.getName());
				}
			}
			if(!StringUtil.isEmpty(lcStatus.getUpdateId())){
				OauthAccountEntity modifiedBy = getAccount(lcStatus.getUpdateId());
				if(null != modifiedBy){
					lcStatus.setModifiedBy(modifiedBy.getName());
				}
			}
		}
		PageInfo<LcStatus> page = new PageInfo<LcStatus>(lcStatusList);
		return outPageBootStr(page,baseSearch);
	}

	/**
	 * 查询单个对象
	 * @param id
	 */
	@ApiOperation(value="查询单个对象", notes="查询单个对象")
	@GetMapping(value="/get/{id}")
	@Auth(value = "/lcStatus/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BaseResult<LcStatus> getLcStatusById(@PathVariable("id")String id){
		LcStatus lcStatus = lcStatusService.getLcStatusById(id);
		if(!StringUtil.isEmpty(lcStatus.getCreateId())){
			OauthAccountEntity createBy = getAccount(lcStatus.getCreateId());
			if(null != createBy){
				lcStatus.setCreateBy(createBy.getName());
			}
		}
		if(!StringUtil.isEmpty(lcStatus.getUpdateId())){
			OauthAccountEntity modifiedBy = getAccount(lcStatus.getUpdateId());
			if(null != modifiedBy){
				lcStatus.setModifiedBy(modifiedBy.getName());
			}
		}
		return outDataStr(lcStatus);
	}

	/**
	 * 添加
	 * @param lcStatus
	 */
	@ApiOperation(value="添加", notes="添加")
	@PostMapping(value="/add")
	public BaseResult addLcStatus(@RequestBody LcStatus lcStatus){
		int i = 0;
		if(null != lcStatus){
			i=lcStatusService.addLcStatus(lcStatus);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 修改
	 * @param lcStatus
	 */
	@ApiOperation(value="修改", notes="修改")
	@PutMapping(value="/update")
	public BaseResult updateLcStatus(@RequestBody LcStatus lcStatus){
		int i = 0;
		if(null != lcStatus){
			i=lcStatusService.updateLcStatus(lcStatus);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@ApiOperation(value="删除", notes="删除")
	@DeleteMapping(value="/delete")
	public BaseResult delLcStatus(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i=lcStatusService.delLcStatus(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 读取数据
	 */
	@ApiOperation(value="读取数据", notes="读取数据")
	@GetMapping(value="/getLcStatusList")
	@Auth(value = "/lcStatus/getLcStatusList",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public List<LcStatus> getLcStatusList(){
		Map<String, Object> condition = new HashMap<String, Object>();
		List<LcStatus> lcStatusList = lcStatusService.getLcStatusListByCondition(condition);
		return lcStatusList;
	}
}